#!usr/bin/env python3
# -*- coding: utf-8 -*-

#自定义的jinja2过滤模板

import time,math
from datetime import datetime,timedelta

#把utc的datetime对象转换成本地的对象,并且去掉小数点
def utcToLocal(utcDt):
	tstamp = utcDt.timestamp() - time.timezone
	tstamp = math.floor(tstamp) #去掉小数点
	return utcDt.fromtimestamp(tstamp)


#自定义jinjia2模板过滤器是个字典
jinjaFilters = {
	"utcToLocal":utcToLocal,
}


#给外部调用
def setFilters(app):
	env = app.jinja_env
	for k,func in jinjaFilters.items():
		if k in env.filters:
			raise KeyError("setFilters trouble:app.jinja_env has filter name '%s' "%str(k))
		env.filters[k] = func
	
		